//
//  FeedBackViewController.m
//  GameBaby
//
//  Created by keyZhang on 14-2-23.
//  Copyright (c) 2014年 keyZhang. All rights reserved.
//

#import "FeedBackViewController.h"
#import "DataService.h"

@interface FeedBackViewController ()

@end

@implementation FeedBackViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        UILabel *t = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
        t.font = [UIFont systemFontOfSize:16];
        t.textColor = [UIColor blackColor];
        t.backgroundColor = [UIColor clearColor];
        t.textAlignment = UITextAlignmentCenter;
        t.text = @"意见反馈";
        self.navigationItem.titleView = t;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)];
    [self.view addGestureRecognizer:tap];
    
    self.txView.layer.cornerRadius = 10;
    self.txView.layer.masksToBounds = YES;
    self.txView.placeholder = @"感谢你的反馈，你的任何建议和意见，甚至是吐槽，对我们来说都非常重要";
//    [self.txView becomeFirstResponder];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"navRightBut"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"navRightButH"] forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(rightBarButton:) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 40, 30);
    [button setTitle:@"提交" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:11];
    button.titleLabel.textColor = [UIColor whiteColor];
    
    //创建导航按钮
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = backBarButtonItem;
}

- (void)tapClick
{
    [self.txView resignFirstResponder];
}

- (void)rightBarButton:(UIButton *)btn
{
    if (self.txView.text.length <= 2) {
        [self showHUD:@"亲,多说点吧" withHiddenDelay:1];
    }else
    {
        NSString *urlStr = [NSString stringWithFormat:@"http://m.a.ewoka.com/user/opinion"];
        NSMutableDictionary *mDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:[[NSUserDefaults standardUserDefaults] objectForKey:@"appid"],@"appid",self.txView.text,@"content", nil];
        __weak FeedBackViewController *this = self;
        [DataService requestWithURL:urlStr
                             params:mDic
                         httpMethod:@"POST"
                        finishBlock:^(id result) {
                            [this loadDataFinished:result];
                        }];
        
        [self showHUD:@"反馈成功" withHiddenDelay:1];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)loadDataFinished:(NSDictionary *)result
{
//    NSLog(@"%@",result);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload {
    [self setTxView:nil];
    [super viewDidUnload];
}

@end
